﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using YiNing.Tools;

namespace LixunYueNan
{
    public partial class Settings : Form
    {
        private LixunArgs lixunArgsLine1, lixunArgsLine2;
        MesPlugin mes;
        public Settings(LixunArgs lixun1, LixunArgs lixun2, ErrorCodes errorCodes, MesPlugin mesPlugin, int selectIndex)
        {
            InitializeComponent();
            mes = mesPlugin;
            lixunArgsLine1 = lixun1;
            lixunArgsLine2 = lixun2;
            propertyGrid1.SelectedObject = lixunArgsLine1;
            propertyGrid2.SelectedObject = lixunArgsLine2;
            propertyGrid3.SelectedObject = errorCodes;
            switch (selectIndex)
            {
                case 1: darkRadioButton1.Checked = true; break;
                case 2: darkRadioButton2.Checked = true; break;
                case 3: darkRadioButton3.Checked = true; break;
                case 4: darkRadioButton4.Checked = true; break;
            }
        }

        private void darkRadioButton1_CheckedChanged(object sender, EventArgs e)
        {
            if (darkRadioButton1.Checked)
            {
                lixunArgsLine1.UnbindEnable = true; lixunArgsLine2.UnbindEnable = false;
            }
            else if(darkRadioButton2.Checked)
            {
                lixunArgsLine1.UnbindEnable = false; lixunArgsLine2.UnbindEnable = true;
            }
            else if (darkRadioButton3.Checked)
            {
                lixunArgsLine1.UnbindEnable = true; lixunArgsLine2.UnbindEnable = true;
            }
            else if (darkRadioButton4.Checked)
            {
                lixunArgsLine1.UnbindEnable = false; lixunArgsLine2.UnbindEnable = false;
            }
            propertyGrid1.SelectedObject = lixunArgsLine1;
            propertyGrid2.SelectedObject = lixunArgsLine2;
        }

        private void darkButton1_Click(object sender, EventArgs e)
        {
            JsonHelper.Serialize(propertyGrid1.SelectedObject as LixunArgs, LixunArgs.GetThisFileName(1));
            JsonHelper.Serialize(propertyGrid2.SelectedObject as LixunArgs, LixunArgs.GetThisFileName(2));
            JsonHelper.Serialize(propertyGrid3.SelectedObject as ErrorCodes, ErrorCodes.GetThisFileName());
            mes.Init(chbEnablePlugin.Checked);
        }
    }
}
